import ToolActionApi from "@/tool/http/tool-action.js";
import ToolConstant from "@/tool/ToolConstant.js";

let serverAppAction = ToolActionApi.init("function_server_app");

let serverAppDict = {}

serverAppAction.dict().then(dict => {
	serverAppDict = dict
})

const rule = {
	queryParams: [],
	formOnChange: (watchForm) => {
		let tempArray = []
		if (watchForm['enum_data_acquisition_type'] === 'RULE_PASSIVE') {
			tempArray.push({ name: "__serverAppId", memo: "服务应用", dictList: serverAppDict })
			if (watchForm['enum_protocol_type'] === 'HTTP' || watchForm['enum_protocol_type'] === 'HTTPS') {
				tempArray.push({ name: "__httpPath", memo: "访问路径" })
				tempArray.push({ name: "__httpType", memo: "请求类型", dictList: ToolConstant.httpTypeDict })
				tempArray.push({ name: "__httpDataType", memo: "传参方式", dictList: ToolConstant.httpDataType })
			}
			if (watchForm['enum_protocol_type'] === 'TCP') {
				// tempArray.push({ name: "__rules", memo: "转换规则", component: NtdDataTcpDetail })
			}
			tempArray.push({ name: "__httpResult", memo: "返回数据" })
		}

		if (watchForm['enum_data_acquisition_type'] === 'RULE_ACTIVE') {
			tempArray.push({ name: "__httpHost", memo: "请求主机" });
			tempArray.push({ name: "__httpPort", memo: "请求端口" });
			tempArray.push({ name: "__httpPath", memo: "请求路径" });
			tempArray.push({ name: "__httpLogicParams", memo: "逻辑参数" });
			tempArray.push({ name: "__httpParams", memo: "请求参数" });
			tempArray.push({ name: "__httpHeaders", memo: "header" });
			tempArray.push({ name: "__httpType", memo: "请求类型", dictList: ToolConstant.httpTypeDict });
			tempArray.push({ name: "__httpDataType", memo: "传参方式", dictList: ToolConstant.httpDataType });
			tempArray.push({ name: "__httpCron", memo: "请求周期(cron)" });
		}
		return tempArray;
	},
	pageConfig: {},
	metaConfig: {},
	baseField: [{
		name: "id"
	}]
}

export default async function(metadata) {
	return rule;
}
